<?php
	
	namespace Aspic\View;
	
	class TwigAdapter implements \Aspic\TemplateLoaderInterface {
		private $_loader;
		private $_env;
		protected $_view;
		
		function __construct($twigDir, $cacheDir, $debug = false) {
			$this->_view = new \Aspic\StdData;
		
			require_once $twigDir.'/Autoloader.php';
			
			\Twig_Autoloader::register();

			$this->_loader = new \Twig_Loader_Filesystem('.');
			
			$this->_env = new \Twig_Environment($this->_loader, array(
			  'cache' => $cacheDir, 
			  'debug' => (bool)$debug
			));
		}
		
		public function setView(\stdclass $view) {
			$this->_view->setVars($view);
		}
		
		public function addTemplatesDir($tplDir) {
			$this->_loader->addPath($tplDir);
		}
		
		public function loadTemplate($templatePath) {
			print $this->_env->render($templatePath, $this->_view->toArray());
		}
		
		public function getLoadedTemplate($templatePath) {
			return $this->_env->render($templatePath, $this->_view->toArray());
		}
	}
	
?>